﻿<%@ Page Title="Xtablish CRM / Invoices" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Invoices.aspx.cs" Inherits="Web.Invoice.Invoices" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Con1" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">

            function setSelectedIndex(combo) {
                combo.trackChanges();
                combo.get_items().getItem(0).select();
                combo.updateClientState();
                combo.commitChanges();
            }
            function ClearClick() {
                clearOrgName();
                var qscombo = $find("<%= ddlStatus.ClientID %>");
                var atcombo = $find("<%= ddlAssignedTo.ClientID %>");
                setSelectedIndex(qscombo);
                setSelectedIndex(atcombo);
            }
            function isPressEnter(evt) {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode == 13) {
                    var clickButton = document.getElementById('<%= btnSearch.ClientID %>');
                    clickButton.click();
                }
            }
            function OnClientClose(oWnd, args) {
                //get the transferred arguments
                var arg = args.get_argument();
                    if (arg) {
                        var searchType = arg.SearchType;
                        if (searchType == "InvoiceNumber") {
                            var oppName = arg.InvoiceNumber;
                            var oppID = arg.InvoiceNumberID;
                        }
                        else if (searchType == "Contact") {
                            var ContactName = arg.ContactName;
                            var ContactID = arg.ContactID;
                            document.getElementById('<%= hdntxtConName.ClientID %>').value = ContactName;
                            document.getElementById('<%= hdntxtConID.ClientID %>').value = ContactID;
                            document.getElementById('<%= txtContactName.ClientID %>').value = ContactName;
                        }

                        else if (searchType == "Organization") {
                            var orgName = arg.OrgName;
                            var orgID = arg.OrgID;
                            document.getElementById('<%= hdntxtOrgName.ClientID %>').value = orgName;
                            document.getElementById('<%= hdntxtOrgID.ClientID %>').value = orgID;
                            document.getElementById('<%= txtOrganizationName.ClientID %>').value = orgName;
                        }
        }
            }

    function clearConName() {
        document.getElementById('<%= hdntxtConName.ClientID %>').value = null;
                document.getElementById('<%= hdntxtConID.ClientID %>').value = null;
                document.getElementById('<%= txtContactName.ClientID %>').value = null;
            }

            function clearOrgName() {
                document.getElementById('<%= hdntxtOrgName.ClientID %>').value = null;
                 document.getElementById('<%= hdntxtOrgID.ClientID %>').value = null;
                 document.getElementById('<%= txtOrganizationName.ClientID %>').value = null;

                 document.getElementById('<%= hdntxtConName.ClientID %>').value = null;
                 document.getElementById('<%= hdntxtConID.ClientID %>').value = null;
                 document.getElementById('<%= txtContactName.ClientID %>').value = null;
             }
             function RowMouseOver(sender, eventArgs) {
                 index = eventArgs.get_itemIndexHierarchical();
             }
             function openRadWin(url, formname) {
                 var orgID = document.getElementById('<%= hdntxtOrgID.ClientID %>').value;
                var orgName = document.getElementById('<%= hdntxtOrgName.ClientID %>').value;
                if (orgID != "")
                    openWin(url + "?OrgID=" + orgID + "&flag=true", formname);
                else
                    ShowMessage("Please choose company name first ! ");
            }
            function openRadwindow(url, formname) {
                var grid = $find("<%= RadGrid1.ClientID %>");
                var masterTableView = grid.get_masterTableView();
                var rbtnPercent, divDiscountPercent, divDiscountPrice;
                var row = masterTableView.get_dataItems()[index];
                var invID = row.getDataKeyValue("InvoiceID");
                openWin(url + invID, formname);
                return false;
            }
            function disableKeyPress(evt) {
                return false;
            }
        </script>
    </telerik:RadCodeBlock>

    <asp:HiddenField ID="hdntxtPrevPage" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtConName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtConID" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtOrgName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtOrgID" runat="server"></asp:HiddenField>
    <div class="register">
        <div class="container-fluid">
            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                <div class="row">
                    <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title">
                                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">Search <i class="glyphicon glyphicon-circle-arrow-down" style="display: none;"></i><i class="glyphicon glyphicon-circle-arrow-up"></i>
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
                            <div class="panel-body">
                                <div class="firstrow">
                                    <div class="edit-form">
                                        <div class="control-group">
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Company Name  </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <asp:TextBox ID="txtOrganizationName" runat="server" class="form-control form-fl" onkeypress="return disableKeyPress(event)" />
                                                        <div class="btn-sl" style="padding-top: 2px">
                                                            <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="openWin('../../SearchPopUp/Organization.aspx?flag=true', 'rwOrganization'); return false;" ToolTip="Search">
                                                                 <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                                            </asp:LinkButton>
                                                            <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="clearOrgName();return false;" ToolTip="Clear">
                                                                 <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                                            </asp:LinkButton>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Contact Name </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <asp:TextBox ID="txtContactName" runat="server" class="form-control" onkeypress="isPressEnter(event)" />
                                                        <div class="btn-sl" style="padding-top: 2px">
                                                            <asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="openRadWin('../../SearchPopUp/Contact.aspx', 'rwContact'); return false;" ToolTip="Search">
                                                                 <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                                            </asp:LinkButton>
                                                            <asp:LinkButton ID="LinkButton4" runat="server" OnClientClick="clearConName();return false;" ToolTip="Clear">
                                                                 <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                                            </asp:LinkButton>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Status </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <telerik:RadComboBox ID="ddlStatus" runat="server" DataTextField="STATUS_NAME" DataValueField="ID" class="form-control"
                                                            Width="80%" Filter="StartsWith" MaxHeight="700px" />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                        <div class="control-group">
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Date Created From </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <telerik:RadDatePicker ID="dpDateCreatedFrom" runat="server" Width="50%">
                                                            <DateInput ReadOnly="true" ID="RadDateInput1" runat="server">
                                                            </DateInput>
                                                            <Calendar ReadOnly="true" ID="Calendar1" runat="server" UseColumnHeadersAsSelectors="False"
                                                                UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                                                <SpecialDays>
                                                                    <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday">
                                                                    </telerik:RadCalendarDay>
                                                                </SpecialDays>
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 distance-control">
                                                <div class="col-md-4">
                                                    <label class="control-label">Date Created To </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <telerik:RadDatePicker ID="dpDateCreatedTo" runat="server" Width="50%">
                                                            <DateInput ReadOnly="true" ID="DateInput2" runat="server">
                                                            </DateInput>
                                                            <Calendar ReadOnly="true" ID="Calendar2" runat="server" UseColumnHeadersAsSelectors="False"
                                                                UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                                                <SpecialDays>
                                                                    <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday">
                                                                    </telerik:RadCalendarDay>
                                                                </SpecialDays>
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-4 distance-control" id="divAssignTo" runat="server">
                                                <div class="col-md-4">
                                                    <label class="control-label">Assign To </label>
                                                </div>
                                                <div class="col-md-8">
                                                    <div class="controls">
                                                        <telerik:RadComboBox ID="ddlAssignedTo" runat="server" class="form-control"
                                                            Width="80%" Filter="StartsWith" MaxHeight="700px" />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="popup-btn">
                                    <div class="col-md-12 btn-edit">
                                        <button id="btnSearch" type="button" class="btn btn-defaul" runat="server" onserverclick="btnSearch_ServerClick">
                                            <img src="../Images/search.png" style="width: 20px; height: 20px" />
                                            Search
                                        </button>
                                        <button class="btn btn-defaul" type="button" onclick="ClearClick();return false;">
                                            <img src="../Images/clear.png" style="width: 20px; height: 20px" />
                                            Clear
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="edit-form highlight">
                        <div class="control-group">
                            <h4>Invoices</h4>
                        </div>
                        <div class="col-md-12 combobox-email">
                            <div class="col-md-8 btn-edit">
                                <button id="btnAddInvoice" type="button" class="btn btn-defaul" runat="server" onserverclick="btnAddInvoice_ServerClick">
                                    <img src="../Images/add.png" style="width: 16px; height: 16px" />
                                    Add Invoice
                                </button>
                               
                                <button id="btnCloseRadWin" type="button" class="btn btn-defaul" runat="server" onserverclick="btnCloseRadWin_ServerClick" causesvalidation="false" style="display: none">
                                    <img src="../Images/add.png" style="width: 16px; height: 16px" />
                                    Add Invoices
                                </button>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div style="width: 100%">
                            <telerik:RadGrid ID="RadGrid1" ShowStatusBar="True" runat="server" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="True" ShowFooter="true"
                                AllowFilteringByColumn="false" AutoGenerateColumns="False" GridLines="None" Width="100%" OnNeedDataSource="RadGrid1_NeedDataSource"
                                Font-Size="12px" OnItemCommand="RadGrid1_ItemCommand" EnableLinqExpressions="false" OnItemCreated="RadGrid1_ItemCreated" OnPreRender="RadGrid1_PreRender">
                                <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="false">
                                    <Selecting AllowRowSelect="false" />
                                    <ClientEvents OnRowMouseOver="RowMouseOver" />
                                </ClientSettings>
                                <MasterTableView PageSize="5" NoDetailRecordsText="No records" NoMasterRecordsText="No records" ShowHeader="true" DataKeyNames="InvoiceID, OrgID" ClientDataKeyNames="InvoiceID" TableLayout="Fixed">
                                    <GroupByExpressions>
                                        <telerik:GridGroupByExpression>
                                            <GroupByFields>
                                                <telerik:GridGroupByField FieldName="ORGANIZATION_NAME"></telerik:GridGroupByField>
                                            </GroupByFields>
                                            <SelectFields>
                                                <telerik:GridGroupByField FieldName="ORGANIZATION_NAME"></telerik:GridGroupByField>
                                            </SelectFields>
                                        </telerik:GridGroupByExpression>
                                    </GroupByExpressions>
                                    <Columns>
                                        <telerik:GridTemplateColumn HeaderText="Seq" UniqueName="TemplateColumn1">
                                            <ItemTemplate>
                                                <asp:Label ID="lblSeq" runat="server" Text="<%# RadGrid1.CurrentPageIndex*RadGrid1.MasterTableView.PageSize + RadGrid1.Items.Count+1 %>">
                                                </asp:Label>
                                            </ItemTemplate>
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="Center" Width="5%" />
                                            <ItemStyle HorizontalAlign="Center" Width="3%" />
                                            <FooterStyle HorizontalAlign="center" Width="3%" BackColor="LightBlue" />
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn DataField="ORGANIZATION_NAME" HeaderText="Company Name " UniqueName="ORGANIZATION_NAME" SortExpression="ORGANIZATION_NAME"
                                            Aggregate="Count" FooterText="Total invoices: ">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="18%" Font-Size="12px" />
                                            <ItemStyle Wrap="false" HorizontalAlign="left" Width="18%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" Font-Bold="true" ForeColor="blue" Font-Size="14px" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CONTACT_NAME" HeaderText="Contact Name" UniqueName="CONTACT_NAME" SortExpression="CONTACT_NAME">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="15%" Font-Size="12px" />
                                            <ItemStyle Wrap="false" HorizontalAlign="left" Width="15%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="15%" BackColor="LightBlue" Font-Bold="true" ForeColor="blue" Font-Size="14px" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="INVOICE_NUMBER" HeaderText="Invoice Number" UniqueName="INVOICE_NUMBER" SortExpression="INVOICE_NUMBER">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="15%" Font-Size="12px" />
                                            <ItemStyle Wrap="false" HorizontalAlign="center" Width="15%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="15%" BackColor="LightBlue" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="DATE_CREATED" HeaderText="Date Created" UniqueName="DATE_CREATED" SortExpression="DATE_CREATED" DataFormatString="{0:d}" DataType="System.DateTime">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" Font-Size="12px" />
                                            <ItemStyle HorizontalAlign="center" Width="10%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="10%" BackColor="LightBlue" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="STATUS_NAME" HeaderText="Status" UniqueName="STATUS_NAME" SortExpression="STATUS_NAME">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" Font-Size="12px" />
                                            <ItemStyle Wrap="false" HorizontalAlign="center" Width="7%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridNumericColumn DataField="TOTAL_PRICE" DataType="System.Decimal" NumericType="Currency" FooterText="Totals"
                                            HeaderText="Total" SortExpression="TOTAL_PRICE" UniqueName="TOTAL_PRICE"
                                            Aggregate="Sum" FooterAggregateFormatString="{0:C}">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="15%" Font-Size="12px" />
                                            <ItemStyle HorizontalAlign="center" Width="15%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" Font-Bold="true" ForeColor="blue" Font-Size="14px" />
                                        </telerik:GridNumericColumn>
                                        <telerik:GridBoundColumn DataField="ASSIGN_TO" HeaderText="Assign To" UniqueName="ASSIGN_TO" SortExpression="ASSIGN_TO">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" Font-Size="12px" />
                                            <ItemStyle Wrap="false" HorizontalAlign="center" Width="10%" Font-Size="12px" />
                                            <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Tools" UniqueName="TOOLS">
                                            <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                            <ItemStyle HorizontalAlign="center" Width="5%" />
                                            <FooterStyle HorizontalAlign="center" Width="5%" BackColor="LightBlue" />
                                            <ItemTemplate>
                                                 <asp:LinkButton ID="lbtnDelete" runat="server" ToolTip="Print" OnClientClick="return openRadwindow('InvoiceReport.aspx?InvoiceID=' ,'rwInvoiceReport');">
                                                    <image src="../Images/printer.png" style="width: 16px; height: 16px"/>
                                                </asp:LinkButton>
                                                 &nbsp
                                                <asp:LinkButton ID="lbtnEdit" runat="server" CommandName="Edit" ToolTip="Edit">
                                                    <image src="../Images/edit.png" style="width: 16px; height: 16px"/>
                                                </asp:LinkButton>
                                                 &nbsp
                                                <asp:LinkButton ID="lbtnView" runat="server" CommandName="View" ToolTip="View">
                                                    <image src="../Images/preview.png" style="width: 16px; height: 16px"/>
                                                </asp:LinkButton>
                                               
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                    </Columns>
                                    <PagerStyle PageSizes="5,10,20,50" PagerTextFormat="{4}<strong>{5}</strong> invoices matching your search criteria"
                                        PageSizeLabelText="Invoices per page:" AlwaysVisible="true" />
                                </MasterTableView>
                                <PagerStyle Mode="NumericPages"></PagerStyle>
                            </telerik:RadGrid>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
